package eerbaar.expression.internal.lib;

import eerbaar.context.IContext;
import eerbaar.context.IParams;
import eerbaar.context.ParamFactory;
import eerbaar.elements.extension.IPoints;
import eerbaar.game.IGame;
import eerbaar.persona.IPersona;

public class CountPointsExpression extends AbstractExpression {

    private static final String[] paramNames = new String[] { "count" };

    private int count;

    private IParams params;

    public CountPointsExpression() {
        super("countPoints");
        this.params = ParamFactory.createParams();
    }

    public CountPointsExpression(IParams params) {
        super("countPoints");
        this.params = params;

        setup(params);
    }

    @Override
    public boolean execute(IContext model) {

        IGame game = (IGame) model;
        IPersona pet = game.getPersona("pet");
        IPoints petPoints = pet.getExtension(IPoints.class);
        int points = petPoints.getPoints();

        return (points >= this.count);
    }

    @Override
    public String[] getParamNames() {

        return paramNames;
    }

    @Override
    public IParams getParams() {

        return this.params;
    }

    @Override
    public void setParams(IParams params) {
        this.params = params;
        setup(params);
    }

    private void setup(IParams params) {

        this.count = Integer.parseInt(params.get("count"));
    }
}
